package br.pesquisa.lsystem.gui;
/*
import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.GraphicsConfiguration;
import java.util.Observable;
import java.util.Observer;

import javax.media.j3d.Alpha;
import javax.media.j3d.Appearance;
import javax.media.j3d.BoundingSphere;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.ColoringAttributes;
import javax.media.j3d.Font3D;
import javax.media.j3d.FontExtrusion;
import javax.media.j3d.RotationInterpolator;
import javax.media.j3d.Shape3D;
import javax.media.j3d.Text3D;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.media.j3d.TransparencyAttributes;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.vecmath.Point3d;
import javax.vecmath.Vector3d;
import javax.vecmath.Vector3f;

import br.pesquisa.lsystem.Celula;
import br.pesquisa.lsystem.Interpretador;

import com.sun.j3d.utils.behaviors.mouse.MouseBehavior;
import com.sun.j3d.utils.behaviors.mouse.MouseRotate;
import com.sun.j3d.utils.behaviors.mouse.MouseTranslate;
import com.sun.j3d.utils.behaviors.mouse.MouseZoom;
import com.sun.j3d.utils.geometry.Box;
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.universe.SimpleUniverse;

class Cell3DPanel1 extends JPanel implements Observer {
	private static final long serialVersionUID = -7022719166045546019L;

	private SimpleUniverse simpleUniverse;
	private Canvas3D canvas3D;

	public Cell3DPanel1() {
	}

	public void init() {
		setLayout(new BorderLayout());
		GraphicsConfiguration graphicsConfiguration = SimpleUniverse
				.getPreferredConfiguration();
		canvas3D = new Canvas3D(graphicsConfiguration);
		add(canvas3D, BorderLayout.CENTER);

		BranchGroup scene = createSceneGraph();
		scene.compile();

		SimpleUniverse simpleUniverse = new SimpleUniverse(canvas3D);
		simpleUniverse.getViewingPlatform().setNominalViewingTransform();

		simpleUniverse.addBranchGraph(scene);
	}

	public BranchGroup createSceneGraph() {
		// Create the root of the branch graph
		BranchGroup objRoot = new BranchGroup();

		// rotate object has composite transformation matrix
		Transform3D xRotation = new Transform3D();
		xRotation.rotX(Math.PI / 4);
		Transform3D rotation = new Transform3D();
		rotation.rotY(Math.PI / 5);
		rotation.mul(xRotation);
		TransformGroup objRotate = new TransformGroup(rotation);
		objRoot.addChild(objRotate);

		TransformGroup objSpin = new TransformGroup();
		objSpin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
		objRotate.addChild(objSpin);

		objSpin.addChild(new ColorCube(0.4));

		Alpha rotationAlpha = new Alpha(-1, 4000);
		RotationInterpolator rotator = new RotationInterpolator(rotationAlpha,
				objSpin);
		BoundingSphere bounds = new BoundingSphere();
		rotator.setSchedulingBounds(bounds);
		objSpin.addChild(rotator);

		return objRoot;
	}

	public void update(Observable o, Object arg) {
		simpleUniverse.cleanup();
		simpleUniverse = new SimpleUniverse(canvas3D);
		simpleUniverse.getViewingPlatform().setNominalViewingTransform();

		int i = (Integer) arg;
		BranchGroup branchGroup = new BranchGroup();
		Transform3D translate = new Transform3D();
		switch(i) {
			case 1:
				translate.setTranslation(new Vector3d(-0.8, 0, 0));
				break;
			case 2:
				translate.setTranslation(new Vector3d(0.8, 0, 0));
				break;
			case 3:
				translate.setTranslation(new Vector3d(0, 0.8, 0));
				break;
			case 4:
				translate.setTranslation(new Vector3d(0, -0.8, 0));
				break;
		}

		TransformGroup transformGroup = new TransformGroup(translate);
		transformGroup.addChild(new ColorCube(0.4));

		branchGroup.addChild(transformGroup);
		branchGroup.compile();

		simpleUniverse.addBranchGraph(branchGroup);
		repaint();
	}

	public static void main(String[] args) throws Exception {
		JFrame frame = new JFrame();
		frame.setLayout(new BorderLayout());

		Cell3DPanel1 panel = new Cell3DPanel1();
		panel.init();
		frame.add(panel, BorderLayout.CENTER);
		frame.setSize(400, 400);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setVisible(true);
		for(int i = 1; i < 5; i++) {
			Thread.sleep(1000);
			panel.update(null, i);
		}
	}
}

public class Cell3DPanel extends CellPanel {
	private static final long serialVersionUID = 7967635688219558511L;

	private Canvas3D canvas3D;
	private SimpleUniverse universe;
	private BranchGroup currentBranchGroup;

	private Appearance cellAppearance;
	private Font3D cellFont;

	public Cell3DPanel(MainFrame frame) {
		super(frame);
	}

	public void init() {
		GraphicsConfiguration configuration = SimpleUniverse.
				getPreferredConfiguration();
		canvas3D = new Canvas3D(configuration);
		canvas3D.setDoubleBufferEnable(true);
		universe = new SimpleUniverse(canvas3D);
		TransformGroup tg = universe.getViewingPlatform().getViewPlatformTransform();
		Transform3D translation = new Transform3D();
		translation.setTranslation(new Vector3d(0, 0, 1));
		tg.setTransform(translation);

		setLayout(new BorderLayout());
		add(canvas3D, BorderLayout.CENTER);

		cellAppearance = new Appearance();
		cellAppearance.setColoringAttributes(new ColoringAttributes(
				0.0f, 1.0f, 0.0f, ColoringAttributes.NICEST));
		cellAppearance.setTransparencyAttributes(new TransparencyAttributes(
				TransparencyAttributes.NICEST, 0.8f));

		Font font = new Font("Arial", Font.PLAIN, 1);
		cellFont = new Font3D(font, new FontExtrusion());
	}

	@Override
	public void doStart() {
//		universe.getViewingPlatform().setNominalViewingTransform();
	}

	@Override
	public void doUpdate(Interpretador<Celula> interpretador) {
		if(currentBranchGroup != null) {
			universe.getLocale().removeBranchGraph(currentBranchGroup);
		}

		currentBranchGroup = new BranchGroup();
		currentBranchGroup.setCapability(BranchGroup.ALLOW_DETACH);

		TransformGroup objRotate = new TransformGroup();
		objRotate.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
		objRotate.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
		currentBranchGroup.addChild(objRotate);
		for(int i = 0; i < interpretador.getEstado().size(); i++) {
			Celula celula = interpretador.getEstado().get(i);
			Transform3D translation = new Transform3D();
			translation.setTranslation(new Vector3f(0.21f * i, 0, 0));
			TransformGroup cellGroup = new TransformGroup(translation);
			cellGroup.addChild(generateCell(celula));

			objRotate.addChild(cellGroup);
		}
		MouseRotate mouseRotate = new MouseRotate();
		mouseRotate.setTransformGroup(objRotate);
		mouseRotate.setSchedulingBounds(new BoundingSphere());
		mouseRotate.setFactor(0.005);
		currentBranchGroup.addChild(mouseRotate);

		TransformGroup viewPlatformTrans = universe.getViewingPlatform().
				getViewPlatformTransform();
		BoundingSphere mouseBounds = new BoundingSphere(new Point3d(), 1000.0);

		MouseTranslate mouseTranslate = new MouseTranslate(
				MouseBehavior.INVERT_INPUT);
		mouseTranslate.setTransformGroup(viewPlatformTrans);
		mouseTranslate.setSchedulingBounds(mouseBounds);
		currentBranchGroup.addChild(mouseTranslate);

		MouseZoom mouseZoom = new MouseZoom(MouseBehavior.INVERT_INPUT);
		mouseZoom.setTransformGroup(viewPlatformTrans);
		mouseZoom.setSchedulingBounds(mouseBounds);
		currentBranchGroup.addChild(mouseZoom);

//		MouseWheelZoom mouseWheelZoom = new MouseWheelZoom(MouseBehavior.INVERT_INPUT);
//		mouseWheelZoom.setTransformGroup(viewPlatformTrans);
//		mouseWheelZoom.setSchedulingBounds(mouseBounds);
//		currentBranchGroup.addChild(mouseWheelZoom);

		currentBranchGroup.compile();
		universe.addBranchGraph(currentBranchGroup);
	}

	private BranchGroup generateCell(Celula celula) {
		BranchGroup branchGroup = new BranchGroup();
		branchGroup.setCapability(BranchGroup.ALLOW_DETACH);
		float length = 0;

		if ("L".equals(celula.getLetra())) {
			length = 0.1f;
		} else if ("S".equals(celula.getLetra())) {
			length = 0.05f;
		} else {
			length = 0.04f;
		}

		branchGroup.addChild(new Box(length, 0.03f, 0.1f, cellAppearance));

		Transform3D translation = new Transform3D();
		translation.setTranslation(new Vector3f(-0.05f, 0.03f, 0.05f));
		translation.setScale(0.1);
		TransformGroup letraGroup = new TransformGroup(translation);

		Text3D text3D = new Text3D(cellFont, celula.getLetra());
		letraGroup.addChild(new Shape3D(text3D));

		branchGroup.addChild(letraGroup);
		branchGroup.compile();

		return branchGroup;
	}

	@Override
	public void doStop(Interpretador<Celula> interpretador) {
	}
}
*/